package br.com.sg5.flx.util
{
	
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.System;
	import flash.system.SystemUpdater;
	
	import mx.containers.FormItem;
	import mx.containers.HBox;
	import mx.containers.VBox;
	import mx.controls.CheckBox;
	import mx.controls.ColorPicker;
	import mx.controls.ComboBox;
	import mx.controls.NumericStepper;
	import mx.controls.RadioButton;
	import mx.controls.Text;
	import mx.controls.TextArea;
	import mx.controls.TextInput;
	import mx.core.Container;
	import mx.core.UIComponentDescriptor;
	
	import spark.components.NavigatorContent;

	public class RotinasUtil
	{
		public function RotinasUtil()
		{
		}
		
		public  function clearAllData(container:Container):void{
			for each(var baseComp:UIComponentDescriptor in container.childDescriptors){
				if (baseComp.id != null){
					if (baseComp.document[baseComp.id] is FormItem){
						search2Level(baseComp.document[baseComp.id]);
					}else{
						clearData(baseComp.document[baseComp.id]);
					}
				}
			}
		}		
		
		private static function search2Level(baseComp:*):void{
			for each(var secComp:UIComponentDescriptor in (baseComp.document[baseComp.id] as FormItem).childDescriptors){
				if (((secComp.type == HBox) || (secComp.type == VBox)) && (secComp.id != null)){
					search3Level(baseComp.document[baseComp.id], secComp.document[secComp.id]);
				}else{
					if (secComp.id != null){ 
						clearData(baseComp.document[baseComp.id].document[secComp.id]);
					}
				}
			}
		}
		
		private static function search3Level(baseComp:*, secComp:*):void{
			for each(var trComp:UIComponentDescriptor in (secComp.document[secComp.id] as HBox).childDescriptors){	
				if (trComp.id != null){
					clearData(baseComp.document[baseComp.id].document[secComp.id].document[trComp.id]);
				}			
			}				
		}
		

		private static function clearData(comp:*):void{
			if (comp.enabled == true){
				switch(comp.className){
					case "TextInput" :
						(comp as TextInput).text = '';
						break;
					case "TextArea" :
						(comp as TextArea).text = '';
						(comp as TextArea).htmlText = '';
						break;					
					case "NumericStepper" :
						(comp as NumericStepper).value = 0;
						break;
					case "RadioButton" :
						(comp as RadioButton).selected = false;
						break;
					case "ComboBox" :
						(comp as ComboBox).selectedIndex = -1;
						break;
					case "ColorPicker" :
						(comp as ColorPicker).selectedColor = new uint(0xffffff);
						break;					
					case "CheckBox" :
						(comp as CheckBox).selected = false;
						break;								
				}
			}
		}
	}
}